#include <stdio.h>

#define TRACE(x...) 
#define PRINT(x...) TRACE(printf(x))

int p[110];
bool days[4000];
int _42;
int d;
int pnum;
int miss;

int main() {
	scanf("%d", &_42);

	while (_42--) {
		scanf("%d", &d);
		scanf("%d", &pnum);

		for (int i=0; i<pnum; i++)
			scanf("%d", &p[i]);

		TRACE(
			printf("days: %d, parties: %d\n", d, pnum);
		)

		for (int i=0; i<d; i++) 
			days[i]=true;

		for (int i=0; i<pnum; i++) {
			for (int j=1; (j*p[i]-1)<=d; j++) {
				days[j*p[i]-1]=false;
				PRINT("%d ", j*(p[i]+1));
			}

			PRINT("\n");
		}

		TRACE(
			for (int i=0; i<d; i++)
				if (days[i]) printf("T ");
				else printf("F ");
				printf("\n");
		)

		miss=0;

		for (int i=0; i<d; i++) {
			if (!days[i] && (i+2)%7!=0 && (i+1)%7!=0) miss++; 
		}	

		printf("%d\n", miss);
	}

	return 0;
}
